import { BasePage } from './../../basePage';
import { IonicPage, Slides } from 'ionic-angular';
import { Component, Injector, ViewChild } from '@angular/core';
import { StorageService } from '../../../providers/StorageService';
import { UserService } from '../../../providers/UserService'
import { PIC_URL } from './../../../providers/Config';


/**
 * Generated class for the MsgcenterPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */


@IonicPage()
@Component({
  selector: 'page-msgcenter',
  templateUrl: 'msgcenter.html',
})
export class MsgcenterPage extends BasePage {

  picture;

  items = [];
  user = {
    user_id: '',
    page_pos: 0,
    page_size: 10,
  };

  shopAgree = {
    pass: 1,
    shop_id: '',
    artist_id: '',
    msg_id: '',
  }

  refuseUsers = {
    shop_id: '',
    user_id: '',
    type: 0,
  }

  constructor(injector: Injector, public stc: StorageService, public userService: UserService) {
    super(injector);
    this.picture = PIC_URL;
    let id = localStorage.userinfo;
    this.user.user_id = JSON.parse(id).user_id;
    this.shopAgree.shop_id = JSON.parse(id).shop_id;
    this.shopAgree.artist_id = JSON.parse(id).artist_id;
    this.refuseUsers.user_id = JSON.parse(id).user_id;
    this.refuseUsers.shop_id = JSON.parse(id).shop_id;
  }

  async ionViewDidLoad() {
console.log(this.user)
    let res = await this.userService.showMyMessageAPI(this.user);
    console.log(res)
    if (res) {
      this.items = res.data;
      console.log(this.items);
    }
  }

  //页面滚动加载数据
  doInfinite(): Promise<any> {
    return new Promise((resolve) => {
      setTimeout(() => {
        let res = this.userService.showMyMessageAPI(this.user);
        this.items.concat(res['data'])
        resolve();
      }, 500);
    })
  }
  // 店铺同意美甲师申请
  async agree() {
    this.shopAgree.pass = 1;
    let res = await this.userService.shopRefuseArtistAPI(this.shopAgree);
    if (res) {
      this.showAlert(res.msg);
    }
  }
  //店铺拒绝申请
  async refuse() {
    this.shopAgree.pass = 0;
    let res = await this.userService.shopRefuseArtistAPI(this.shopAgree);
    if (res) {
      this.showAlert(res.msg);
    }
  }
  //美甲师拒绝邀请
  async refuseUser() {
    this.refuseUsers.type = 0;
    let res = await this.userService.artistRejectInvAPI(this.refuse);
    if (res) {
      this.showAlert(res.msg);
    }
  }
  // 美甲师同意邀请
  async agreeUser() {
    this.refuseUsers.type = 1;
    let res = await this.userService.artistRejectInvAPI(this.refuse);
    if (res) {
      this.showAlert(res.msg);
    }
  }


  /*回到个人中心*/
  gotop() {
    this.viewCtrl.dismiss();
  }

}
